package com.ease.util {

   import flash.external.ExternalInterface;

   internal class FirefoxBrowserInfo implements IBrowserInfo {
      private var _name:String = BrowserUtil.BROWSER_FIREFOX;
      private var _version:String = null;
      private var _os:String = null;
      private var _arch:String = null;
      private var _cookieEnabled:Boolean = false;

      public function get version():String {
         return _version;
      }

      public function get name():String {
         return _name;
      }

      public function get os():String {
         return _os;
      }

      public function get arch():String {
         return _arch;
      }

      public function get cookieEnabled():Boolean {
         return _cookieEnabled;
      }

      public function detect(ua:String):Boolean {
         // 0: Full User Agent, e.g. "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8"
         // 1: Mozilla Version, e.g. "5.0"
         // 2: Platform, e.g. "X11"
         // 3: OS specifics, e.g. "; U; Linux i686; pl-PL; rv:1.9.0.2)"
         // 7: Version, e.g. "3.8"
         var re:RegExp = /Mozilla\/(.*?) \((Windows|Macintosh|X11)(.*?) Gecko\/(\d.*?) ((\w.*)\/(\d[^ ]*))?/i;
         var m:Object = re.exec(ua);

         if (m == null) {
            return false;
         }

         if (m[3].indexOf("Linux") > -1) {
            var lre:RegExp = new RegExp(".*(Linux) (.*?);.*", "i");

            var lm:Object = lre.exec(m[3]);

            if (lm != null) {
               _os = lm[1];
               _arch = lm[2];
            }
         } else {
            _os = m[2];
         }

         _version = m[7];
         _cookieEnabled = ExternalInterface.call("function() {return window.navigator.cookieEnabled;}");

         return true;
      }
   }

}